package com.ruoyi.life.service.impl;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.life.domain.LifeSchedule;
import com.ruoyi.life.mapper.LifeScheduleMapper;
import com.ruoyi.life.service.ILifeScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 日程Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-28
 */
@Service
public class LifeScheduleServiceImpl implements ILifeScheduleService {
    @Autowired
    private LifeScheduleMapper lifeScheduleMapper;

    /**
     * 查询日程
     *
     * @param id 日程主键
     * @return 日程
     */
    @Override
    public LifeSchedule selectLifeScheduleById(Long id) {
        return lifeScheduleMapper.selectLifeScheduleById(id);
    }

    /**
     * 查询日程列表
     *
     * @param lifeSchedule 日程
     * @return 日程
     */
    @Override
    public List<LifeSchedule> selectLifeScheduleList(LifeSchedule lifeSchedule) {
        List<LifeSchedule> lifeSchedules = lifeScheduleMapper.selectLifeScheduleList(lifeSchedule);
        if (lifeSchedules != null && lifeSchedules.size() > 0) {
            for (LifeSchedule schedule : lifeSchedules) {
                String plan = StrUtil.replace(schedule.getLiPlan(), "<p>", "");
                plan = StrUtil.replace(plan, "</p>", "");
                plan = StrUtil.replace(plan, "<br>", "");
                schedule.setLiPlan(plan);
            }


        }
        return lifeSchedules;
    }

    /**
     * 新增日程
     *
     * @param lifeSchedule 日程
     * @return 结果
     */
    @Override
    public int insertLifeSchedule(LifeSchedule lifeSchedule) {
        lifeSchedule.setCreateTime(DateUtils.getNowDate());
        return lifeScheduleMapper.insertLifeSchedule(lifeSchedule);
    }

    /**
     * 修改日程
     *
     * @param lifeSchedule 日程
     * @return 结果
     */
    @Override
    public int updateLifeSchedule(LifeSchedule lifeSchedule) {
        return lifeScheduleMapper.updateLifeSchedule(lifeSchedule);
    }

    /**
     * 批量删除日程
     *
     * @param ids 需要删除的日程主键
     * @return 结果
     */
    @Override
    public int deleteLifeScheduleByIds(Long[] ids) {
        return lifeScheduleMapper.deleteLifeScheduleByIds(ids);
    }

    /**
     * 删除日程信息
     *
     * @param id 日程主键
     * @return 结果
     */
    @Override
    public int deleteLifeScheduleById(Long id) {
        return lifeScheduleMapper.deleteLifeScheduleById(id);
    }
}
